package com.portal.back.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.portal.back.service.ISysMessageService;
import com.portal.back.service.impl.SysMessageService;
import com.portal.base.web.BaseAction;

import com.portal.domain.SysMessage;

/**
 * @Title:留言Action
 * @Copyright: Copyright (c) 0.1
 * @author:鲁根成
 * @version: 1.0
 * @time: 2011-4-13
 * 
 */
@SuppressWarnings("serial")
public class SysMessageAction extends BaseAction {
	private ISysMessageService service;

	public SysMessageAction() {
		service = new SysMessageService();
	}

	public String getAllMessage() {
		List<SysMessage> list = service.getAllMessage();
		ActionContext context = ActionContext.getContext();
		context.put("list", list);
		return "getallMessage";

	}

	public String deleteMessage() {
		String deleteByIdString = request.getParameter("id");
		boolean isFlag = service.deleteById(deleteByIdString);
		response.setContentType("text/html;charset=gbk");
		PrintWriter out = null;
		if (isFlag)
			message = "删除成功";
		else
			message = "删除失败";
		StringBuffer sb = new StringBuffer("[");
		sb.append("{\"message\":\"" + message + "\"" + "}");
		sb.append("]");

		try {
			out = response.getWriter();
			out.println(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public String getMessageById() {
		String id = request.getParameter("id");
		SysMessage message = service.getById(id);
		ActionContext context = ActionContext.getContext();
		context.put("message", message);
		return "somemessage";
	}
}
